package com.yoomiito.app.ui.my.stock

import com.yoomiito.app.base.AppConfig
import com.yoomiito.app.base.BaseLazyFragmentPresenter
import com.yoomiito.app.model.bean.OrderList
import com.yoomiito.app.net.YmApi

import cn.droidlover.xdroidmvp.net.ApiException
import cn.droidlover.xdroidmvp.net.ApiSubscriber
import cn.droidlover.xdroidmvp.net.XApi
import com.yoomiito.app.model.bean.OrderInfo
import com.yoomiito.app.model.bean.StockBean

class StockFmPresenter(appConfig: AppConfig) : BaseLazyFragmentPresenter<StockFragment>(appConfig) {

    fun queryStockList(page: Int, type: Int, productId: String) {
        YmApi.getYmService()
            .queryStockList(page, type, productId)
            .compose(v.bindToLifecycle())
            .compose(XApi.getApiTransformerData<StockBean>())
            .compose(XApi.getScheduler())
            .subscribe(object : ApiSubscriber<StockBean>() {
                override fun onSuccess(orderList: StockBean) {
                    v.setData(orderList)
                }

                override fun onFail(error: ApiException) {

                }
            })
    }

    fun recommendDetail(type: String, productId: Int) {
        YmApi.getYmService()
            .recommendDetail(type, productId)
            .compose(v.bindToLifecycle())
            .compose(XApi.getApiTransformerData<OrderInfo>())
            .compose(XApi.getScheduler())
            .subscribe(object : ApiSubscriber<OrderInfo>() {
                override fun onSuccess(orderList: OrderInfo) {
                    v.setdatas(orderList)
                }

                override fun onFail(error: ApiException) {

                }
            })
    }

}
